import java.util.*;
import java.util.LinkedList;

public class Find {
    static boolean debug = true;

    public static void main(String[] args) {
        LinkedList<Integer> list = new LinkedList<>();
        Scanner scanner = new Scanner(System.in);
        System.out.println("Please enter integers (ends with not-an-int input)");
        while (true) {
            try {
                list.add(scanner.nextInt());
            } catch (Exception e) {
                scanner.next();
                break;
            }
        }

        int[] arr = new int[list.size()];
        int i = 0;
        while (!list.isEmpty()) {
            arr[i++] = list.removeFirst();
        }
        System.out.printf("got array (length %d):",arr.length);
        System.out.println(Arrays.toString(arr));
        while (true) {
            try {
                System.out.println("num to search:");
                System.out.println(find(scanner.nextInt(), arr));
            } catch (Exception e) {
                scanner.next();
                System.out.println("welcome to use again");
                scanner.close();
                break;
            }
        }
    }

    static int find(int datum, int[] arr_sorted) {
        int low = 0, high = arr_sorted.length - 1;
        int mid;
        while (low <= high) {

            mid = (low + high) / 2;
            if (debug)
                System.out.printf("high :%d\tmid:%d\tlow:%d\n", high, mid, low);
            if (arr_sorted[mid] == datum)
                return mid;
            if (arr_sorted[mid] > datum)
                high = mid - 1;
            else
                low = mid + 1;
        }
        return -1;
    }
}
